#include "Wmo.h"
#include "WmoGroup.h"

Wmo::Wmo()
{
}

Wmo::~Wmo()
{
}

void Wmo::Load(std::string path)
{
	FILE* file = std::fopen(path.c_str(), "rb");

	std::fseek(file, 0x14, SEEK_SET);	// Skip MOHD

	std::fread(&m_oHeader, sizeof(WmoMohd), 1, file);

	unsigned char	chunkName[4];
	unsigned int	length;
	
	std::fread(chunkName, sizeof(unsigned char), 4, file);	// Skip MOTX
	std::fread(&length, sizeof(unsigned int), 1, file);
	std::fseek(file, length, SEEK_CUR);

	m_pMaterials = new WmoMomt[m_oHeader.MaterialCount];

	std::fseek(file, 8, SEEK_CUR);
	std::fread(m_pMaterials, sizeof(WmoMomt), m_oHeader.MaterialCount, file);

	std::fread(chunkName, sizeof(unsigned char), 4, file);	// Skip MOTX
	std::fread(&length, sizeof(unsigned int), 1, file);
	std::fseek(file, length, SEEK_CUR);

	m_pGroupInformations = new WmoMogi[m_oHeader.GroupCount];

	std::fread(chunkName, sizeof(unsigned char), 4, file);	// Skip MOGI
	std::fread(&length, sizeof(unsigned int), 1, file);
	//std::fread(m_pGroupInformations, sizeof(WmoMogi), m_oHeader.GroupCount, file);	// Something wrong here.
	std::fseek(file, length, SEEK_CUR);

	// TODO: The rest.

	std::fclose(file);
}